package top.minuy.structure.graph.sort;

import top.minuy.res.graph.GraphRes;
import top.minuy.structure.graph.representations.table.Graph;

/**
 * 拓扑排序测试
 *
 * @author Minuy
 * @time 13:30
 * @date 2021/11/27
 */
public class Test {
    public static void main(String[] args) {
        System.out.println("经典拓扑排序：");
       testTs(GraphRes.G_TOPOLOGICAL_SORT_01);
       testTs(GraphRes.G_TOPOLOGICAL_SORT_02);

        System.out.println("另一个拓扑排序：");
        testTsd(GraphRes.G_TOPOLOGICAL_SORT_01);
        testTsd(GraphRes.G_TOPOLOGICAL_SORT_02);
    }

    private static void testTs(String path) {
        Graph g = new Graph(path,true);
        TopologicalSort ts = new TopologicalSort(g);
        if (ts.hasCycle()){
            System.out.println("Graph has cycle.");
        }else {
            System.out.println(ts.sortResult());
        }
    }

    private static void testTsd(String path) {
        Graph g = new Graph(path,true);
        TopologicalSortDFS ts = new TopologicalSortDFS(g);
        if (ts.hasCycle()){
            System.out.println("Graph has cycle.");
        }else {
            System.out.println(ts.sortResult());
        }
    }
}
